/**
 * 
 */
package com.jm.web.tags.table;

import com.jm.utils.StringHelper;
import com.jm.web.builder.table.TdBuilder;
import com.jm.web.tags.support.BaseFormItemTag;

/**
 * @author yanjie
 * Jan 30, 2012 2:25:41 PM
 */
public class TdTag extends BaseFormItemTag{
	private static final long serialVersionUID = -3968292202709908313L;
	protected TrTag trTag = null;
	
	@Override
	protected int onStartTag() {
		if(this.getPage().isExport() && !this.isEp()){
			return SKIP_BODY;
		}
		return EVAL_BODY_BUFFERED;
	}
	
	@Override
	protected void preStartTag() {
		if(this.getParent() != null && this.getParent() instanceof TrTag){
			this.trTag = (TrTag)this.getParent();
		}
		super.preStartTag();
	}
	
	public TrTag getTrTag() {
		return trTag;
	}
	
	@Override
	public void clear() {
		trTag = null; 
		super.clear();
	}
	
	/**
	 * @param strValue
	 */
	public void setMerge(String strValue) {
		SetExtValue("merge",strValue);
	}
	
	
	
	public void setAlign(String strValue) {
		SetExtValue("align",strValue);
	}
	
	public void setText(String strValue) {
		SetExtValue("text",strValue);
	}
	
	public void setCid(String strValue) {
		SetExtValue("cid",strValue);
	}
	
	public void setColspan(String strValue) {
		SetExtValue("colspan",strValue);
	}
	
	public void setRowspan(String strValue) {
		SetExtValue("rowspan",strValue);
	}
	
	@Override
	public String getBuilderName() {
		return TdBuilder.class.getName();
	}
	
	/**
	 * @return
	 * group 合并
	 */
	public boolean isAutoMerge1(){
		return "true".equals(this.GetExtValue("merge",""));
	}
	
	/**
	 * @return
	 * subGroup 合并
	 */
	public boolean isAutoMerge2(){
		if("false".equals(this.GetExtValue("merge","")))return false;
		return !StringHelper.IsNullOrEmpty(this.GetExtValue("merge",""));
	}
	
	/**
	 * @param strValue
	 * 小計,可以有好幾個
	 */
	public void setSubTotal(String strValue) {
		SetExtValue("subTotal",strValue);
	}
	
	/**
	 * @param strValue
	 * 總計只會有一個
	 */
	public void setGrandSubtotal(String strValue) {
		SetExtValue("grandTotal",strValue);
	}
	
	/**
	 * @return
	 */
	public boolean isAutoMerge(){
		return this.isAutoMerge1() || this.isAutoMerge2();
	}
	
	public String getSubGroup(){
		if("true".equals(this.GetExtValue("merge","")) 
				|| "false".equals(this.GetExtValue("merge","")))
			return "";
		return this.GetExtValue("merge","");
	}
}
